@extends('layouts.application')

@section('css')
    <link rel="stylesheet" href="/vendor/daterangepicker/daterangepicker.css">
    <style>
        .am-icon-male {
            color: #2ca02c;
        }
        .am-icon-female {
            color: red;
        }
    </style>
@endsection

@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">会员列表</strong> /
                    <small>Customer List</small>
                </div>
            </div>

            <br>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-um-12">
                    <form class="am-form-inline" role="form" method="get">
                        <div class="am-form-group am-input-group-sm">
                            <input type="text" name="name" class="am-form-field" placeholder="会员名称"
                                   value="{{Request::input('name')}}">
                        </div>

                        <div class="am-form-group am-input-group-sm">
                            <input type="text" name="openid" class="am-form-field" placeholder="微信OPEN_ID"
                                   value="{{Request::input('name')}}">
                        </div>

                        <div class="am-form-group am-input-group-sm">
                            <select name="sex" data-am-selected="{btnSize: 'sm'}">
                                <option value="-1">选择性别</option>
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </div>

                        <div class="am-form-group">
                            <input type="text" id="created_at" placeholder="选择注册时间" name="created_at"
                                   value="{{ Request::input('created_at') }}" class="am-form-field am-input-sm">
                        </div>

                        <div class="am-input-group am-input-group-sm">
                            <button class="am-btn am-btn-default am-btn-sm" type="submit">查询</button>
                        </div>

                        <div class="am-input-group am-input-group-sm">
                            <a href="{{route('shop.customer.index')}}" class="am-btn am-btn-default am-btn-sm">重置</a>
                        </div>
                    </form>
                </div>

            </div>


            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check">
                                    <input type="checkbox" class="check_all"/>
                                </th>
                                <th>编号</th>
                                <th>头像</th>
                                <th>昵称</th>
                                <th>opendid</th>
                                <th>性别</th>
                                <th>关注时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach($customers as $customer)
                                <tr data-id="{{$customer->id}}">
                                    <td>
                                        <input type="checkbox" name="check_id[]" value=""
                                               class="checked_id"/>
                                    </td>
                                    <td>{{$customer->id}}</td>
                                    <td>
                                        <img src="{{$customer->thumb}}" alt="" style="width: 50px;height: 50px;">
                                    </td>
                                    <td>{{$customer->nickname}}</td>
                                    <td>{{$customer->openid}}</td>
                                    <td>

                                        {!! is_sex($customer,'sex') !!}

                                    </td>
                                    <td>{{$customer->created_at}}</td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href=""
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary">
                                                    <span class="am-icon-list-alt"></span> 查看订单
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$customers->total()}} 条记录
                            <div class="am-fr">
                                <ul class="am-pagination">

                                    {{$customers->appends(Request::all())->links()}}

                                </ul>
                            </div>
                        </div>
                        <hr/>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>
    </div>
@endsection

@section('js')
    <script src="/vendor/daterangepicker/moment.js"></script>
    <script src="/vendor/daterangepicker/daterangepicker.js"></script>
    <script src="/vendor/moment/locale/zh-cn.js"></script>
    <script src="/js/daterange_config.js"></script>

    <script>
        $(function () {
            //上面选中，下面也选中
            $('.check_all').click(function () {
                var checked = $(this).prop('checked');
                $('.checked_id').prop('checked', checked);
            });

            //改变属性
            $('.change_attr').click(function () {
                var id = $(this).parents('tr').data('id');
                var attr = $(this).attr('data-attr');
                var _this = $(this);

                $.ajax({
                    type: 'PATCH',
                    url: '{{route('shop.customer.change_attr')}}',
                    data: {id: id, attr: attr},
                    success: function () {
                        _this.toggleClass('am-icon-male am-icon-female');
                    }
                });
                return false;
            });
        })
    </script>
@endsection